
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";

//入库操作请求API
export const publicPropsApi = createApi({
    reducerPath: 'publicprops',
    //设置基本请求路径
    baseQuery: fetchBaseQuery({
        baseUrl: window.app
    }),
    tagTypes:['publicprops'],//定义标签
    endpoints(build) {
        return {
            //获取入库记录
            getpublicprops: build.query({
                query:(para) =>({
                    url: 'Admin_Props/GetPropsAdmin',
                    method:'GET',
                    params:para,
                }),
                transformResponse(baseQuery){
                    return baseQuery;

                },
                providesTags:['publicprops']//定义标签，如果该标签失效则会触发重新访问服务器
            }),
           
           
            //修改一条商品入库记录
            puteditpublicprops: build.mutation({
                query(data) {
                    return {
                        url: 'Admin_Props/EditPropsAdmin',
                        method: 'PUT',
                        body:data
                    };
                },
                transformResponse(baseQuery){
                    return baseQuery.data;

                },
                invalidatesTags:['publicprops']//定义标签，一旦修改数据，则会使该标签失效
            }),
            
            
        }
    }
});


//导出钩子函数给外部使用，自动生成hooks的名称为`use(Endpoint_name)Query`
export const { useGetpublicpropsQuery,usePuteditpublicpropsMutation } = publicPropsApi;